home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Scrolling / Scrolling.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.2 KB  |  430 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class Scrolling extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    // $FF: renamed from: b java.awt.Graphics
  20.    private Graphics field_0;
  21.    private Image buffer;
  22.    private Image backImage;
  23.    private boolean loaded = false;
  24.    private boolean isBackImage = false;
  25.    private boolean paintable = false;
  26.    private boolean move = true;
  27.    private boolean firstime = true;
  28.    // $FF: renamed from: wi int
  29.    private int field_1;
  30.    // $FF: renamed from: he int
  31.    private int field_2;
  32.    private int wiBack;
  33.    private int heBack;
  34.    private int decy;
  35.    private int pause;
  36.    private int text_height;
  37.    private int pas;
  38.    // $FF: renamed from: X int
  39.    private int field_3;
  40.    private int long_string;
  41.    private Color textColor;
  42.    private String backImageName;
  43.    private String text;
  44.    private Color backColor;
  45.    // $FF: renamed from: fm java.awt.FontMetrics
  46.    private FontMetrics field_4;
  47.    private Color enterBackColor;
  48.    private Color enterTextColor;
  49.    private AudioClip sound;
  50.    private AudioClip clicSound;
  51.    private AudioClip enterSound;
  52.    private boolean loopSound;
  53.    private String link;
  54.    private String statusBarText;
  55.  
  56.    public String getAppletInfo() {
  57.       return "Name: Scrolling\r\nAuthor: Taiji Software\r\n";
  58.    }
  59.  
  60.    public Scrolling() {
  61.       this.move = true;
  62.       this.pause = 5;
  63.       this.text_height = 10;
  64.       this.pas = 3;
  65.       ((Component)this).addMouseListener(this);
  66.    }
  67.  
  68.    public void register() {
  69.       try {
  70.          URL u = new URL("http://www.taijisoftware.com");
  71.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  72.       } catch (Exception e) {
  73.          System.out.println(e);
  74.          this.stop();
  75.       }
  76.    }
  77.  
  78.    public void init() {
  79.       String codeBase = null;
  80.  
  81.       try {
  82.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  83.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  84.          codeBase = codeBase.toUpperCase();
  85.       } catch (Exception var9) {
  86.       }
  87.  
  88.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  89.          String regCode = ((Applet)this).getParameter("registration_code");
  90.          if (regCode == null) {
  91.             regCode = ((Applet)this).getParameter("reg_domain");
  92.             if (regCode == null) {
  93.                this.register();
  94.             } else {
  95.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  96.                   codeBase = "WWW." + codeBase;
  97.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  98.                   codeBase = codeBase.substring(4);
  99.                }
  100.  
  101.                char[] chars = new char[codeBase.length()];
  102.                codeBase.getChars(0, codeBase.length(), chars, 0);
  103.                String key = new String("haricot");
  104.                char[] chars2 = new char[key.length()];
  105.                key.getChars(0, key.length(), chars2, 0);
  106.  
  107.                for(int i = 0; i < codeBase.length(); ++i) {
  108.                   int j;
  109.                   if (i >= key.length()) {
  110.                      j = i - key.length() * (i / key.length());
  111.                   } else {
  112.                      j = i;
  113.                   }
  114.  
  115.                   chars[i] += chars2[j];
  116.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  117.                }
  118.  
  119.                String res = new String(chars);
  120.                if (!res.equalsIgnoreCase(regCode)) {
  121.                   this.register();
  122.                }
  123.             }
  124.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  125.             this.register();
  126.          }
  127.       }
  128.  
  129.       this.getParameters();
  130.       if (this.sound != null) {
  131.          if (this.loopSound) {
  132.             this.sound.loop();
  133.             return;
  134.          }
  135.  
  136.          this.sound.play();
  137.       }
  138.  
  139.    }
  140.  
  141.    public void getParameters() {
  142.       String s = ((Applet)this).getParameter("pause");
  143.       if (s != null) {
  144.          this.pause = Integer.parseInt(s);
  145.       }
  146.  
  147.       this.field_1 = ((Component)this).getSize().width;
  148.       this.field_2 = ((Component)this).getSize().height;
  149.       this.text = ((Applet)this).getParameter("text");
  150.       if (this.text == null) {
  151.          this.text = "no text !!";
  152.       }
  153.  
  154.       this.textColor = this.getColor("text_color");
  155.       this.backColor = this.getColor("background_color");
  156.       ((Component)this).setBackground(this.backColor);
  157.       s = ((Applet)this).getParameter("text_height");
  158.       if (s != null) {
  159.          this.text_height = Integer.parseInt(s);
  160.       }
  161.  
  162.       s = ((Applet)this).getParameter("height_shift");
  163.       if (s != null) {
  164.          this.decy = Integer.parseInt(s);
  165.       }
  166.  
  167.       s = ((Applet)this).getParameter("step");
  168.       if (s != null) {
  169.          this.pas = Integer.parseInt(s);
  170.       }
  171.  
  172.       this.backImageName = ((Applet)this).getParameter("background_image");
  173.       if (this.backImageName != null) {
  174.          this.isBackImage = true;
  175.       }
  176.  
  177.       this.field_3 = this.field_1;
  178.       this.enterBackColor = this.getColor("enter_background_color");
  179.       this.enterTextColor = this.getColor("enter_text_color");
  180.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  181.       s = ((Applet)this).getParameter("sound_name");
  182.       if (s != null) {
  183.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  184.       }
  185.  
  186.       s = ((Applet)this).getParameter("loop_sound");
  187.       if (s != null) {
  188.          if (s.equals("yes")) {
  189.             this.loopSound = true;
  190.          } else {
  191.             this.loopSound = false;
  192.          }
  193.       }
  194.  
  195.       s = ((Applet)this).getParameter("clic_sound_name");
  196.       if (s != null) {
  197.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  198.       }
  199.  
  200.       s = ((Applet)this).getParameter("enter_sound_name");
  201.       if (s != null) {
  202.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  203.       }
  204.  
  205.       this.link = ((Applet)this).getParameter("link");
  206.    }
  207.  
  208.    public Color getColor(String param) {
  209.       String s = ((Applet)this).getParameter(param);
  210.       if (s != null) {
  211.          if (s.substring(0, 1).equals("#")) {
  212.             s = s.substring(1);
  213.             int i = Integer.parseInt(s, 16);
  214.             return new Color(i);
  215.          } else {
  216.             return null;
  217.          }
  218.       } else {
  219.          return null;
  220.       }
  221.    }
  222.  
  223.    public final void paint(Graphics g) {
  224.       if (this.paintable) {
  225.          this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  226.          if (this.isBackImage & this.loaded) {
  227.             this.field_0.drawImage(this.backImage, (this.field_1 - this.wiBack) / 2, (this.field_2 - this.heBack) / 2, this);
  228.          }
  229.  
  230.          this.field_0.drawString(this.text, this.field_3, this.text_height + this.decy);
  231.          g.drawImage(this.buffer, 0, 0, this);
  232.       }
  233.  
  234.    }
  235.  
  236.    public final void update(Graphics g) {
  237.       this.paint(g);
  238.    }
  239.  
  240.    public void start() {
  241.       this.move = true;
  242.       if (this.thread == null) {
  243.          this.thread = new Thread(this);
  244.          this.thread.start();
  245.       }
  246.  
  247.    }
  248.  
  249.    public void stop() {
  250.       if (this.thread != null) {
  251.          this.move = false;
  252.          this.thread = null;
  253.       }
  254.  
  255.       if (this.sound != null) {
  256.          this.sound.stop();
  257.       }
  258.  
  259.    }
  260.  
  261.    public void run() {
  262.       if (this.firstime) {
  263.          if (this.isBackImage) {
  264.             MediaTracker tracker = new MediaTracker(this);
  265.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  266.             tracker.addImage(this.backImage, 0);
  267.  
  268.             try {
  269.                tracker.waitForAll();
  270.                this.loaded = !tracker.isErrorAny();
  271.             } catch (InterruptedException var5) {
  272.                this.stop();
  273.             }
  274.  
  275.             if (!this.loaded) {
  276.                this.stop();
  277.                return;
  278.             }
  279.          }
  280.  
  281.          this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  282.          this.field_0 = this.buffer.getGraphics();
  283.          String fontName = ((Applet)this).getParameter("text_font");
  284.          if (fontName == null) {
  285.             fontName = "TimesRoman";
  286.          }
  287.  
  288.          int style = 1;
  289.          String s = ((Applet)this).getParameter("text_style");
  290.          if (s != null) {
  291.             if (s.equals("bold")) {
  292.                style = 1;
  293.             } else if (s.equals("italic")) {
  294.                style = 2;
  295.             } else if (s.equals("bold_italic")) {
  296.                style = 3;
  297.             } else {
  298.                style = 0;
  299.             }
  300.          }
  301.  
  302.          this.field_0.setFont(new Font(fontName, style, this.text_height));
  303.          if (this.isBackImage) {
  304.             this.wiBack = this.backImage.getWidth(this);
  305.             this.heBack = this.backImage.getHeight(this);
  306.          }
  307.  
  308.          this.field_4 = this.field_0.getFontMetrics();
  309.          if (this.decy == 0) {
  310.             this.decy = (this.field_2 + this.field_4.getMaxAscent() - this.field_4.getMaxDescent()) / 2 - this.text_height;
  311.          }
  312.  
  313.          this.long_string = this.field_4.stringWidth(this.text);
  314.          this.field_0.setColor(this.textColor);
  315.          this.paintable = true;
  316.          this.firstime = false;
  317.       }
  318.  
  319.       while(this.move) {
  320.          ((Component)this).repaint();
  321.          this.field_3 -= this.pas;
  322.          if (this.field_3 < -this.long_string) {
  323.             this.field_3 = this.field_1;
  324.          }
  325.  
  326.          try {
  327.             Thread.sleep((long)this.pause);
  328.          } catch (InterruptedException e) {
  329.             System.err.println(e);
  330.             this.stop();
  331.          }
  332.       }
  333.  
  334.    }
  335.  
  336.    public URL giveURL(String url) {
  337.       try {
  338.          if (url.toUpperCase().startsWith("HTTP")) {
  339.             return new URL(url);
  340.          } else if (url.toUpperCase().startsWith("FTP")) {
  341.             int p = url.indexOf(":");
  342.             int p2 = url.indexOf(":", p + 1);
  343.             if (p2 != -1) {
  344.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  345.             }
  346.  
  347.             p = url.indexOf("%40");
  348.             if (p != -1) {
  349.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  350.             }
  351.  
  352.             return new URL(url);
  353.          } else {
  354.             return new URL(((Applet)this).getCodeBase(), url);
  355.          }
  356.       } catch (MalformedURLException e) {
  357.          System.out.println(e);
  358.          return null;
  359.       }
  360.    }
  361.  
  362.    public void mouseClicked(MouseEvent e) {
  363.    }
  364.  
  365.    public void mouseEntered(MouseEvent e) {
  366.       if (this.enterBackColor != null) {
  367.          ((Component)this).setBackground(this.enterBackColor);
  368.          ((Component)this).repaint();
  369.       }
  370.  
  371.       if (this.enterTextColor != null) {
  372.          if (this.field_0 != null) {
  373.             this.field_0.setColor(this.enterTextColor);
  374.          }
  375.  
  376.          ((Component)this).repaint();
  377.       }
  378.  
  379.       if (this.statusBarText != null) {
  380.          ((Applet)this).showStatus(this.statusBarText);
  381.       }
  382.  
  383.       if (this.enterSound != null) {
  384.          this.enterSound.play();
  385.       }
  386.  
  387.       if (this.link != null) {
  388.          ((Component)this).setCursor(new Cursor(12));
  389.       }
  390.  
  391.    }
  392.  
  393.    public void mouseExited(MouseEvent e) {
  394.       if (this.enterBackColor != null) {
  395.          ((Component)this).setBackground(this.backColor);
  396.          ((Component)this).repaint();
  397.       }
  398.  
  399.       if (this.enterTextColor != null) {
  400.          this.field_0.setColor(this.textColor);
  401.          ((Component)this).repaint();
  402.       }
  403.  
  404.       if (this.link != null) {
  405.          ((Component)this).setCursor(new Cursor(0));
  406.       }
  407.  
  408.    }
  409.  
  410.    public void mousePressed(MouseEvent e) {
  411.       if (this.clicSound != null) {
  412.          this.clicSound.play();
  413.       }
  414.  
  415.       if (this.link != null) {
  416.          String target = ((Applet)this).getParameter("target");
  417.          if (target == null) {
  418.             target = "_blank";
  419.          }
  420.  
  421.          URL u = this.giveURL(this.link);
  422.          ((Applet)this).getAppletContext().showDocument(u, target);
  423.       }
  424.  
  425.    }
  426.  
  427.    public void mouseReleased(MouseEvent e) {
  428.    }
  429. }
  430.